import {createStore, applyMiddleware} from 'redux'
import thunkMiddleware from 'redux-thunk'
import {hashHistory} from 'react-router'
import {routerMiddleware} from 'react-router-redux'
import createLogger from 'redux-logger'

import promiseMiddleware from './middlewares/promiseMiddleware'

import rootReducer from './reducers'
import initState from './initState'

const loggerMiddleware = createLogger({
    level: 'info',
    collapsed: true
});

/**
 * 创建store中间件
 *
 */
const createStoreWithMiddleware = applyMiddleware(
    thunkMiddleware,
    promiseMiddleware({promiseTypeSuffixes: ['PENDING', 'SUCCESS', 'ERROR']}),
    loggerMiddleware,
    routerMiddleware(hashHistory)
)(createStore);

const store = createStoreWithMiddleware(rootReducer, initState);

export default store
